package o;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.zip.Inflater;
import o.ah.g;

public final class ajz extends ajh {
    private Inflater ˊ;
    private final a ˎ = new a();
    private final anc ˏ = new anc();
    private final anc ॱ = new anc();

    static final class a {
        private int ʻ;
        private int ʽ;
        private boolean ˊ;
        private int ˋ;
        private int ˎ;
        private final anc ˏ = new anc();
        private final int[] ॱ = new int[256];
        private int ॱॱ;
        private int ᐝ;

        private void ˋ(anc o_anc, int i) {
            if (i % 5 == 2) {
                o_anc.ˎ(2);
                Arrays.fill(this.ॱ, 0);
                int i2 = i / 5;
                for (int i3 = 0; i3 < i2; i3++) {
                    int ʽ = o_anc.ʽ();
                    int ʽ2 = o_anc.ʽ();
                    int ʽ3 = o_anc.ʽ();
                    int ʽ4 = o_anc.ʽ();
                    int ʽ5 = o_anc.ʽ();
                    int i4 = (int) (((double) ʽ2) + (1.402d * ((double) (ʽ3 - 128))));
                    ʽ3 = (int) ((((double) ʽ2) - (0.34414d * ((double) (ʽ4 - 128)))) - (0.71414d * ((double) (ʽ3 - 128))));
                    ʽ2 = (int) (((double) ʽ2) + (1.772d * ((double) (ʽ4 - 128))));
                    this.ॱ[ʽ] = anr.ॱ(ʽ2, 0, 255) | ((anr.ॱ(ʽ3, 0, 255) << 8) | ((ʽ5 << 24) | (anr.ॱ(i4, 0, 255) << 16)));
                }
                this.ˊ = true;
            }
        }

        private void ˎ(anc o_anc, int i) {
            if (i >= 4) {
                int ˏॱ;
                o_anc.ˎ(3);
                int i2 = i - 4;
                if (((o_anc.ʽ() & DnsConfig.MAX_CACHE_ENTRIES) != 0 ? 1 : null) != null) {
                    if (i2 >= 7) {
                        ˏॱ = o_anc.ˏॱ();
                        if (ˏॱ >= 4) {
                            this.ᐝ = o_anc.ॱॱ();
                            this.ʻ = o_anc.ॱॱ();
                            this.ˏ.ˏ(ˏॱ - 4);
                            i2 -= 7;
                        } else {
                            return;
                        }
                    }
                    return;
                }
                ˏॱ = this.ˏ.ˋ();
                int ॱ = this.ˏ.ॱ();
                if (ˏॱ < ॱ && i2 > 0) {
                    i2 = Math.min(i2, ॱ - ˏॱ);
                    o_anc.ˎ(this.ˏ.ˏ, ˏॱ, i2);
                    this.ˏ.ˋ(i2 + ˏॱ);
                }
            }
        }

        private void ॱ(anc o_anc, int i) {
            if (i >= 19) {
                this.ˎ = o_anc.ॱॱ();
                this.ˋ = o_anc.ॱॱ();
                o_anc.ˎ(11);
                this.ॱॱ = o_anc.ॱॱ();
                this.ʽ = o_anc.ॱॱ();
            }
        }

        public Cue ˎ() {
            if (this.ˎ == 0 || this.ˋ == 0 || this.ᐝ == 0 || this.ʻ == 0 || this.ˏ.ॱ() == 0 || this.ˏ.ˋ() != this.ˏ.ॱ() || !this.ˊ) {
                return null;
            }
            this.ˏ.ˋ(0);
            int[] iArr = new int[(this.ᐝ * this.ʻ)];
            int i = 0;
            while (i < iArr.length) {
                int ʽ = this.ˏ.ʽ();
                if (ʽ != 0) {
                    int i2 = i + 1;
                    iArr[i] = this.ॱ[ʽ];
                    i = i2;
                } else {
                    int ʽ2 = this.ˏ.ʽ();
                    if (ʽ2 != 0) {
                        if ((ʽ2 & 64) == 0) {
                            ʽ = ʽ2 & 63;
                        } else {
                            ʽ = ((ʽ2 & 63) << 8) | this.ˏ.ʽ();
                        }
                        Arrays.fill(iArr, i, i + ʽ, (ʽ2 & DnsConfig.MAX_CACHE_ENTRIES) == 0 ? 0 : this.ॱ[this.ˏ.ʽ()]);
                        i += ʽ;
                    }
                }
            }
            return new Cue(Bitmap.createBitmap(iArr, this.ᐝ, this.ʻ, Config.ARGB_8888), ((float) this.ॱॱ) / ((float) this.ˎ), 0, ((float) this.ʽ) / ((float) this.ˋ), 0, ((float) this.ᐝ) / ((float) this.ˎ), ((float) this.ʻ) / ((float) this.ˋ));
        }

        public void ˋ() {
            this.ˎ = 0;
            this.ˋ = 0;
            this.ॱॱ = 0;
            this.ʽ = 0;
            this.ᐝ = 0;
            this.ʻ = 0;
            this.ˏ.ˏ(0);
            this.ˊ = false;
        }
    }

    public ajz() {
        super("PgsDecoder");
    }

    protected aji ˎ(byte[] bArr, int i, boolean z) throws SubtitleDecoderException {
        this.ˏ.ॱ(bArr, i);
        ˊ(this.ˏ);
        this.ˎ.ˋ();
        List arrayList = new ArrayList();
        while (this.ˏ.ˊ() >= 3) {
            Cue ˏ = ˏ(this.ˏ, this.ˎ);
            if (ˏ != null) {
                arrayList.add(ˏ);
            }
        }
        return new ajy(Collections.unmodifiableList(arrayList));
    }

    private void ˊ(anc o_anc) {
        if (o_anc.ˊ() > 0 && o_anc.ʻ() == g.ॱˍ) {
            if (this.ˊ == null) {
                this.ˊ = new Inflater();
            }
            if (anr.ॱ(o_anc, this.ॱ, this.ˊ)) {
                o_anc.ॱ(this.ॱ.ˏ, this.ॱ.ॱ());
            }
        }
    }

    private static Cue ˏ(anc o_anc, a aVar) {
        Cue cue = null;
        int ॱ = o_anc.ॱ();
        int ʽ = o_anc.ʽ();
        int ॱॱ = o_anc.ॱॱ();
        int ˋ = o_anc.ˋ() + ॱॱ;
        if (ˋ > ॱ) {
            o_anc.ˋ(ॱ);
        } else {
            switch (ʽ) {
                case 20:
                    aVar.ˋ(o_anc, ॱॱ);
                    break;
                case 21:
                    aVar.ˎ(o_anc, ॱॱ);
                    break;
                case 22:
                    aVar.ॱ(o_anc, ॱॱ);
                    break;
                case DnsConfig.MAX_CACHE_ENTRIES /*128*/:
                    cue = aVar.ˎ();
                    aVar.ˋ();
                    break;
            }
            o_anc.ˋ(ˋ);
        }
        return cue;
    }
}
